package org.example.hello4_routingKey_direct;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 路由模式,生产者不需要绑定队列，rabbitTemplate直接往往交换机携带路由key发送信息
 * 消费者只需要知道生产者的交换机和路由key
 */
@Component
public class RoutingDirectCoustmer {

    /**
     * 接收第一个队列里的信息
     * *匹配路由键的一个词
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(   //把队列和交换机进行绑定
            value=@Queue(value = "info_queue", durable = "true", autoDelete = "false"),     //绑定队列
            key = {"routingKey_info"},
            exchange = @Exchange(name = "directs_exchange",type= ExchangeTypes.DIRECT)   //绑定交换机
    ))
    public void receive1(String message){
        System.out.println("info-消费者【1】接收到消息"+message);
    }


    /**
     * 接收第二个队列里的信息
     * #号匹配路由键的一个或多个词
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "warm_queue", durable = "true", autoDelete = "false"),
            exchange = @Exchange(value = "directs_exchange", type = ExchangeTypes.DIRECT), key = "routingKey_warm"))
    public void receive2(String message){
        System.out.println("warm-消费者【2】接收到消息"+message);
    }

}
